package top.hardsnail.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import top.hardsnail.mapper.IBaseMapper;
import top.hardsnail.service.IBaseService;

import java.util.List;

/**
 * @author Tre'
 * @date 2021/2/28 13:55
 */
public abstract class BaseServiceImpl<T> implements IBaseService<T> {
    // service层中调用mapper层，该属性需要子类实例化，必须要实例化
    //private IBaseMapper<T> baseMapper;(原-修改访问权限修饰符) //这里没有声明，没有实例化
    // 定义成抽象方法的原因是强制要求子类复写，不写编译不过去
    protected abstract IBaseMapper<T> baseMapper();

    @Override
    public int add(T t) {
        return baseMapper().add(t);
    }

    @Override
    public Integer update(T t) {
        return baseMapper().update(t);
    }

    @Override
    public Integer delete(Integer id) {
        return baseMapper().deleteById(id);
    }

    @Override
    public T selectById(Integer id) {
        return baseMapper().selectById(id);
    }

    @Override
    public PageInfo getPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List list = baseMapper().getList();

        return new PageInfo<T>(list);
    }
}
